<template>
  <page-header-wrapper>
    <applicationSearch @search="handleSearch" @reset="handleReset"></applicationSearch>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: true }"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
          <y-button type="link" class="text-error" @click="handleDistriButionCancer(record)">取消分配</y-button>
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis, applicationSearch } from '@/components'
import { getDistributionManagement, postDistriButionHouse } from '@/api/DistrictReviewReportManagement'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    applicationSearch,
  },
  data() {
    return {
      queryParam: {
        Mode: 'UnassignManagement',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 80,
          fixed: 'left',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请编号',
          align: 'center',
          fixed: 'left',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          fixed: 'left',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          fixed: 'left',
          dataIndex: 'IDCard',
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'Phone',
        },
        {
          title: '分配信息',
          align: 'center',
          dataIndex: 'EsitesSelect',
          customRender: (text) => <ellipsis length={40}>{text}</ellipsis>,
        },
        {
          title: '分配时间',
          align: 'center',
          dataIndex: 'ESetDate',
          customRender: (text) => moment(text).format('YYYY-MM-DD'),
        },
        {
          title: '区县',
          align: 'center',
          dataIndex: 'RegionName',
        },
        {
          title: '社区/街道',
          align: 'center',
          dataIndex: 'TownshipName',
        },
        {
          title: '核定保障人数',
          align: 'center',
          dataIndex: 'CityVfyNumber',
        },
        {
          title: '保障类型',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'BZ',
        },
        {
          title: '操作',
          align: 'center',
          width: '140px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getDistributionManagement(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.$refs.table.refresh(true)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'districtMaterialObjectCancelDetail',
        params: {
          id,
        },
      })
    },
    handleDistriButionCancer(record) {
      this.$confirm({
        title: '提示',
        content: '是否确定该用户取消分配？',
        onOk: () => {
          return postDistriButionHouse({
            State: 'cancel',
            HousesID: record.Esites,
            UserID: this.$store.getters.userid,
            ProposerID: record.ID,
          }).then((res) => {
            this.$message.success('取消实物分配成功')
            this.$refs.table.refresh()
          })
        },
      })
    },
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-table td {
  white-space: nowrap;
}
</style>
